package net.wanho.servlet;

import com.alibaba.fastjson.JSON;
import net.wanho.entity.Emp;
import net.wanho.service.EmpService;
import net.wanho.service.impl.EmpServiceImpl;
import net.wanho.util.AjaxResult;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

/**
 * Author：汤小洋
 * Date：2024-07-30 13:52
 * Description：<描述>
 */
@WebServlet("/listEmp")
public class ListEmpServlet extends HttpServlet {

    private EmpService empService = new EmpServiceImpl();

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        List<Emp> list = empService.findAll();

        resp.setHeader("Access-Control-Allow-Origin","*");
        resp.setContentType("application/json;charset=utf8");
        PrintWriter out = resp.getWriter();
        out.print(JSON.toJSONString(AjaxResult.success(list)));
        out.close();
    }
}
